package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.MemberBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.basethem.TintManager;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.DateUtil;

import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/21
 * 未认证的会员
 */

public class MembernoAdapter extends BaseAdapter {
    private List<MemberBean.MemberMessageBean> specailList;
    private LayoutInflater mInflater;
    private Context mContext = null;
    OnMembersClickslister onClickListener;

    public MembernoAdapter(Context context, List<MemberBean.MemberMessageBean> specailList) {
        this.mContext = context;
        this.specailList = specailList;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<MemberBean.MemberMessageBean> specailList) {
        this.specailList = specailList;
        notifyDataSetChanged();
    }

    /**
     * 设置回调接口
     *
     * @param onClickListener
     */
    public void setOnMembersClicksListener(OnMembersClickslister onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnMembersClickslister {
        public void OnClickMems(int postion);
    }

    @Override
    public int getCount() {
        return specailList.size();
    }

    @Override
    public Object getItem(int position) {
        return specailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_nomember, null);
            holder = new ViewHolder();
            holder.memno_phone = (TextView) convertView.findViewById(R.id.memno_phone);
            holder.memno_name = (TextView) convertView.findViewById(R.id.memno_name);
            holder.memno_img = (ImageView) convertView.findViewById(R.id.memno_img);
            holder.memno_days_text = (TextView) convertView.findViewById(R.id.memno_days_text);
            holder.memno_time_text = (TextView) convertView.findViewById(R.id.memno_time_text);
            holder.memno_pay = (ImageView) convertView.findViewById(R.id.memno_pay);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (specailList.size() > 0) {
            MemberBean.MemberMessageBean bean = specailList.get(position);
            if (bean != null) {
                String path = C.qiniu_ip + bean.getPhoto();
                GildeUtils.loadUrlImage4(path, holder.memno_img, mContext);
                holder.memno_name.setText(bean.getName());
                holder.memno_phone.setText(bean.getMobile());

                holder.memno_phone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
                holder.memno_phone.getPaint().setAntiAlias(true);//抗锯齿

                holder.memno_phone.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(mContext).getSystemConfig().getColor()));

                if (bean.getCountdown() != null && StringUtils.isNotEmpty(bean.getCountdown())) {
                    if (bean.getCountdown().equals("-1")) {
                        holder.memno_days_text.setText("0天");
                    } else {
                        holder.memno_days_text.setText(bean.getCountdown() + "天");
                    }
                } else {
                    holder.memno_days_text.setText("暂无");
                }
                if (bean.getCreateDate() != null && StringUtils.isNotEmpty(bean.getCreateDate())) {
                    holder.memno_time_text.setText(DateUtil.strToDate(bean.getCreateDate()));
                } else {
                    holder.memno_time_text.setText("暂无");
                }
                String pay = bean.getIsPay();//1是已支付
                if ("1".equals(pay)) {
                    holder.memno_pay.setVisibility(View.VISIBLE);
                } else {
                    holder.memno_pay.setVisibility(View.GONE);
                }

                holder.memno_phone.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onClickListener.OnClickMems(position);
                    }
                });
            }
        }
        return convertView;
    }


    class ViewHolder {
        TextView memno_name;
        TextView memno_phone;
        ImageView memno_img;
        TextView memno_days_text;
        TextView memno_time_text;
        ImageView memno_pay;
    }
}
